package com.ghck.server;

import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.security.AuthenticationManagerConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration;
import org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration;
import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import com.ghck.server.aop.ApiAccessAspect;
import com.ghck.server.config.AspectjConfig;
import com.ghck.server.config.CacheConfiguration;
import com.ghck.server.config.ControllerConfig;
import com.ghck.server.config.DatasourceConfig;
import com.ghck.server.config.ResourceConfig;
import com.ghck.server.config.RestSecurityConfiguration;
import com.ghck.server.config.UserProfile;
import com.ghck.server.config.remote.HttpInvokerClientConfig;
import com.ghck.server.config.remote.HttpInvokerServerConfig;
import com.ghck.server.utils.SpringContextUtil;

@Configuration
@Import({
	 DispatcherServletAutoConfiguration.class
	,EmbeddedServletContainerAutoConfiguration.class
	,ErrorMvcAutoConfiguration.class
	,HttpEncodingAutoConfiguration.class
	,HttpMessageConvertersAutoConfiguration.class
	,MultipartAutoConfiguration.class
	,ServerPropertiesAutoConfiguration.class
	,PropertyPlaceholderAutoConfiguration.class
	,WebMvcAutoConfiguration.class
	,SecurityAutoConfiguration.class
	,AuthenticationManagerConfiguration.class
	
	,ResourceConfig.class
	,SpringContextUtil.class
	,HttpInvokerClientConfig.class
	,DatasourceConfig.class
	,CacheConfiguration.class
	,HttpInvokerServerConfig.class
	,ControllerConfig.class
	,RestSecurityConfiguration.class,
	AspectjConfig.class
        
})
//@ComponentScan
public class GhckAplication {
	
	private static Logger log = LoggerFactory.getLogger(GhckAplication.class);
	
	public final static String all = "permitAll";
	public final static String user = "hasAnyAuthority('USER')";
	public final static String maker = "hasAnyAuthority('MAKER')";
	public final static String maker_user = "hasAnyAuthority('MAKER','USER')";
	public final static String shop = "hasAnyAuthority('SHOP')";
	public final static String shop_user = "hasAnyAuthority('SHOP','USER')";
	public final static String shop_maker = "hasAnyAuthority('SHOP','MAKER')";
	public final static String shop_maker_user = "hasAnyAuthority('SHOP','MAKER','USER')";
	public final static String admin_customer_service_shop_maker_user = "hasAnyAuthority('ADMIN','CUSTOMER_SERVICE','SHOP','MAKER','USER')";
	public final static String customer_service = "hasAnyAuthority('CUSTOMER_SERVICE')";
	public final static String admin = "hasAnyAuthority('ADMIN')";
	public final static String admin_shop = "hasAnyAuthority('ADMIN','SHOP')";
	public final static String admin_shop_maker = "hasAnyAuthority('ADMIN','SHOP','MAKER')";
	
	public static void main(String[] args) {
		log.info("System.getProperty(spring.profiles.active) : {}",System.getProperty("spring.profiles.active"));
		if(System.getProperty("spring.profiles.active")==null){
			log.info("默认为null");
			System.setProperty("spring.profiles.active", UserProfile.INTG);
		}
		log.info("System.getProperty(spring.profiles.active) : {}",System.getProperty("spring.profiles.active"));
		
		Map<String, String> env = System.getenv();
		log.info("env : {}",env);
		Properties properties =  System.getProperties();
		log.info("properties : {}",properties);
		Iterator<Object> iterator = properties.keySet().iterator();
		while (iterator.hasNext()){
			Object obj =  iterator.next();
			log.info("{} : ",obj);
		}
		
		SpringApplication.run(GhckAplication.class, args);
		
		//StartUpCheckService startUpCheckService = SpringContextUtil.getBean(StartUpCheckService.class);
		//startUpCheckService.startUpCheck();
	}
}
